---
layout: "default"
keywords: ""
root: "/v5.1"
title: "print"
description: "Swift documentation for 'print'"
---

<div class="intro-declaration"><code class="language-swift">func print(_:separator:terminator:)(_ items: Any, separator: String = " ", terminator: String = "\n")</code></div><div class="discussion comment"><p>Writes the textual representations of the given items into the standard
output.
</p>
<p>You can pass zero or more items to the <code>print(_:separator:terminator:)</code>
function. The textual representation for each item is the same as that
obtained by calling <code>String(item)</code>. The following example prints a string,
a closed range of integers, and a group of floating-point values to
standard output:</p>
<pre><code class="language-swift">print(&quot;One two three four five&quot;)
// Prints &quot;One two three four five&quot;

print(1...5)
// Prints &quot;1...5&quot;

print(1.0, 2.0, 3.0, 4.0, 5.0)
// Prints &quot;1.0 2.0 3.0 4.0 5.0&quot;
</code></pre>
<p>To print the items separated by something other than a space, pass a string
as <code>separator</code>.</p>
<pre><code class="language-swift">print(1.0, 2.0, 3.0, 4.0, 5.0, separator: &quot; ... &quot;)
// Prints &quot;1.0 ... 2.0 ... 3.0 ... 4.0 ... 5.0&quot;
</code></pre>
<p>The output from each call to <code>print(_:separator:terminator:)</code> includes a
newline by default. To print the items without a trailing newline, pass an
empty string as <code>terminator</code>.</p>
<pre><code class="language-swift">for n in 1...5 {
    print(n, terminator: &quot;&quot;)
}
// Prints &quot;12345&quot;
</code></pre>
</div><div class="intro-declaration"><code class="language-swift">func print(_:separator:terminator:to:)(_ items: Any, separator: String = " ", terminator: String = "\n", to output: inout Target)</code></div><div class="discussion comment"><p>Writes the textual representations of the given items into the given output
stream.
</p>
<p>You can pass zero or more items to the <code>print(_:separator:terminator:to:)</code>
function. The textual representation for each item is the same as that
obtained by calling <code>String(item)</code>. The following example prints a closed
range of integers to a string:</p>
<pre><code class="language-swift">var range = &quot;My range: &quot;
print(1...5, to: &amp;range)
// range == &quot;My range: 1...5\n&quot;
</code></pre>
<p>To print the items separated by something other than a space, pass a string
as <code>separator</code>.</p>
<pre><code class="language-swift">var separated = &quot;&quot;
print(1.0, 2.0, 3.0, 4.0, 5.0, separator: &quot; ... &quot;, to: &amp;separated)
// separated == &quot;1.0 ... 2.0 ... 3.0 ... 4.0 ... 5.0\n&quot;
</code></pre>
<p>The output from each call to <code>print(_:separator:terminator:to:)</code> includes a
newline by default. To print the items without a trailing newline, pass an
empty string as <code>terminator</code>.</p>
<pre><code class="language-swift">var numbers = &quot;&quot;
for n in 1...5 {
    print(n, terminator: &quot;&quot;, to: &amp;numbers)
}
// numbers == &quot;12345&quot;
</code></pre>
</div>